package com.zhanglingfei.yuekaoshop;


import com.zhanglingfei.yuekaoshop.entity.Brand;
import com.zhanglingfei.yuekaoshop.repository.BrandRepository;
import com.zhanglingfei.yuekaoshop.repository.CategoryRepository;
import com.zhanglingfei.yuekaoshop.repository.OrderRepository;
import com.zhanglingfei.yuekaoshop.repository.SpuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.event.ObjectChangeListener;
import java.util.List;

@RestController
public class TestController {

    @Autowired
    private BrandRepository brandRepository;

    @GetMapping("test")
    public Object test(Brand brandQuery) {
        Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "letter");
        Page<Brand> all = brandRepository.findAll(pageable);

        Brand brand = new Brand();
        if (brandQuery.getName() != null) {
            brand.setName(brandQuery.getName());
        }
        Example<Brand> example = Example.of(brand);
        Page<Brand> all1 = brandRepository.findAll(example, pageable);

        List<Brand> bList = brandRepository.getListByName("%".concat(brandQuery.getName()).concat("%"));
        return bList;
    }

    @Autowired
    private OrderRepository orderRepository;

    @Autowired
    private SpuRepository spuRepository;


    @Autowired
    private CategoryRepository categoryRepository;


    @GetMapping("test2")
    public Object test2(Long id) {
//        return orderRepository.findById(id);
//        return spuRepository.findById(id);
        return categoryRepository.findById(id);
    }

}
